package 异常;

import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner sr=new Scanner(System.in);
        while(true){
            try {
                System.out.println("输入一个价格");
                String priceString=sr.nextLine();
                double price=Double.valueOf(priceString);
                if (price>=0){
                    System.out.println("价格为："+price);
                    break;
                }else {
                    System.out.println("价格输入错误");
                }
            } catch (NumberFormatException e) {
                System.out.println("不要乱输入价格");
            }
        }
    }
}
